package com.example.myapplication.data.database

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.example.myapplication.data.model.StorageSpace
import java.util.UUID

/**
 * 储物空间数据库实体
 */
@Entity(tableName = "storage_spaces")
data class StorageSpaceEntity(
    @PrimaryKey 
    val id: String = UUID.randomUUID().toString(),
    
    @ColumnInfo(name = "name")
    val name: String,
    
    @ColumnInfo(name = "description")
    val description: String? = null,
    
    @ColumnInfo(name = "parent_id")
    val parentId: String? = null,
    
    @ColumnInfo(name = "icon_type")
    val iconType: String? = null,
    
    @ColumnInfo(name = "created_at")
    val createdAt: Long = System.currentTimeMillis(),
    
    @ColumnInfo(name = "updated_at")
    val updatedAt: Long = System.currentTimeMillis()
)

/**
 * Entity转换为Model
 */
fun StorageSpaceEntity.toModel(): StorageSpace = StorageSpace(
    id = id,
    name = name,
    description = description,
    parentId = parentId,
    iconType = iconType,
    createdAt = createdAt,
    updatedAt = updatedAt
)

/**
 * Model转换为Entity
 */
fun StorageSpace.toEntity(): StorageSpaceEntity = StorageSpaceEntity(
    id = id,
    name = name,
    description = description,
    parentId = parentId,
    iconType = iconType,
    createdAt = createdAt,
    updatedAt = updatedAt
) 